package {
	import flash.events.MouseEvent;	
	
	import com.googlecode.milib.vo.MLEvent;	
	
	import flash.display.MovieClip;
	import flash.events.KeyboardEvent;
	
	import com.googlecode.milib.MILibMain;
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.dbg.SimpleTrace;
	import com.googlecode.milib.service.singleton.KeyboardService;
	import com.googlecode.milib.service.singleton.MouseService;
	import com.googlecode.milib.vo.MLEventInfo;		

	/**
	 * @author Marek Brun 'minim'
	 */
	public class CapturingEvents extends MovieClip implements IMLBroadcasterListener {

		private var ks:KeyboardService;
		private var ms:MouseService;

		public function CapturingEvents() {
			MILibMain.init(this);
			MILibMain.getInstance().setupStandardStage();
			
			ks=KeyboardService.getInstance();
			ks.addListener(this);
			
			ms=MouseService.getInstance();
			ms.addEventListener(ms.event_Down, onMouseDown);
			ms.addListener(this);
		}
		
//********************************************************************************************
//		events for CapturingEvents
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case ks:
					switch(ev.event) {
						case ks.event_Down:
							SimpleTrace.trace('ks.event_Down keyCode:' +KeyboardEvent(ev.data).keyCode);
						break;
					}
				break;
				case ms:
					switch(ev.event) {
						case ms.event_Down:
							SimpleTrace.trace('ms.event_Down from broadcaster');
						break;
						case ms.event_Arrive:
							SimpleTrace.trace('ms.event_Arrive from broadcaster');
						break;
						case ms.event_Leave:
							SimpleTrace.trace('ms.event_Leave from broadcaster');
						break;
						case ms.event_Up:
							SimpleTrace.trace('ms.event_Up from broadcaster');
						break;
						case ms.event_Whell:
							SimpleTrace.trace('ms.event_Whell from broadcaster delta'+MouseEvent(ev.data).delta);
							break;
					}
				break;
			}
		}
		
		protected function onMouseDown(event:MLEvent):void {
			SimpleTrace.trace('onMouseDown');
		}
	}
}
